#ifndef _WINDOW_HANDLER_H_
#define _WINDOW_HANDLER_H_

#include "../sleipner_config.h"
#include <string>
// abstract interface for defining window-handling code.
// we'll have different versions of this code that handles builds 
// for different platforms

#ifdef _NOLOCALIZATION_
#define QUIT_YESNO "Are you sure you want to quit?"
#endif

class	WindowHandler
{
public:
	WindowHandler() :
		m_Width(0), m_Height(0),
		m_x(0), m_y(0),
		m_IsPaused(false),
		m_IsDestroyed(false),
		m_IsFullscreen(false),
		m_HasFocus(false),
		m_IsInitialized(false),
		m_IsWidescreen(false), m_IsNativeWidescreen(false), m_ResolutionChanged(false),
		m_OrigWidth(0), m_OrigHeight(0),m_OrigDepth(0),
		m_MouseX(0), m_MouseY(0),
		m_AbsMouseX(0), m_AbsMouseY(0),
		m_MouseInsideClient(true),
		m_IsQuitting(false)
	{
	}
	virtual			~WindowHandler() {};

// all windows need to handle the following events.
	virtual bool		InitWindow(const std::string& Name, const std::string& Title, int	X, int Y, int Width, int Height) = 0;
	virtual bool		InitGraphics() = 0;
	virtual bool		DestroyWindow() = 0;
	virtual bool		Tick(float dt) = 0;
	virtual void		ResetDevice() = 0;

	virtual bool		OnGainFocus() = 0;
	virtual bool		OnLooseFocus() = 0;
// do whatever the system needs to update it's message pump
	virtual bool		UpdateOS() = 0;


// not applicable to all, but for most

	virtual bool		Minimize() = 0;
	virtual bool		Maximize() = 0;
	virtual void		SwitchFullscreen(int Width, int Height) = 0;
	virtual void		SwitchWindowed(int Width, int Height) = 0;

	virtual std::string	GetSaveFolder() = 0;
	virtual bool		SetCursor(const std::string& File) = 0;

// functions to change screen resolution around
	virtual bool	GetNativeResolution(unsigned int& Width, unsigned int& Height, unsigned int &Depth) { Width = m_OrigWidth; Height = m_OrigHeight, Depth = m_OrigDepth; return true; };
	virtual bool	GetCurrentResolution(unsigned int& Width, unsigned int& Height, unsigned int &Depth)= 0;
	virtual bool	SetResolution(unsigned int Width, unsigned int Height, unsigned int Depth)= 0;
	virtual bool	RestoreResolution() = 0;
	virtual bool	DetectWidescreenMode() = 0;


// accessors for all windowhandlers
	const std::string&	GetName() const { return m_AppName;	};
	const std::string&	GetTitle() const { return m_Title;	};				
	unsigned int		GetWidth() const { return m_Width;	};
	unsigned int		GetHeight()const { return m_Height;	};
	unsigned int		GetTLX() const { return m_x;		};
	unsigned int		GetTLY() const { return m_y;		};
	unsigned int		GetOrigWidth() const { return m_OrigWidth;		};
	unsigned int		GetOrigHeight() const { return m_OrigHeight;		};
	unsigned int		GetOrigDepth() const { return m_OrigDepth;		};
	virtual int			ScreenWidth() const { return m_BaseWidth; }
	virtual int			ScreenHeight() const { return m_BaseHeight; }

	bool				IsPaused() const { return m_IsPaused;};
	bool				IsDestroyed() const { return m_IsDestroyed;};
	bool				IsFullscreen() const { return m_IsFullscreen;};
	void				SetFullscreen(bool b) { m_IsFullscreen = b;};
	bool				HasFocus() const { return m_HasFocus;};
	bool				IsInitialized() const { return m_IsInitialized; };
	bool				IsWidescreen() const { return m_IsWidescreen; };
	void				SetIsNativeWideScreen(bool b){ m_IsNativeWidescreen = b; };
	bool				IsNativeWidescreen() const { return m_IsNativeWidescreen; };
	bool				IsResolutionChanged() const { return m_ResolutionChanged; }
	bool				IsMouseInsideClient() const { return m_MouseInsideClient || IsFullscreen(); }
	void				SetIsQuitting() { m_IsQuitting = true; };

	void				SetWidth(unsigned int w){m_Width = w;};
	void				SetHeight(unsigned int h){m_Height = h;};

protected:
	std::string			m_AppName;					//! Application name
	std::string			m_Title;					//! Application title
	unsigned int		m_Width, m_Height;			//! Current Window size.
	unsigned int		m_BaseWidth, m_BaseHeight;	//! The viewport area we're dealing with
	unsigned int		m_OrigWidth, m_OrigHeight, m_OrigDepth;	//! Original screen resolution. If we change it, it's polite to restore later
	unsigned int		m_x, m_y;					//! Position of top-left coordinate
	bool				m_IsPaused;
	bool				m_IsDestroyed;
	bool				m_IsFullscreen;
	bool				m_IsWidescreen, m_IsNativeWidescreen, m_ResolutionChanged;
	bool				m_HasFocus;
	bool				m_IsInitialized;
	bool				m_IsQuitting;

	float				m_MouseX, m_MouseY;			//! Mouse X/Y in 0..1 coordinates
	int					m_AbsMouseX, m_AbsMouseY;	//! Mouse X/Y in 0..Width/0..Height coordinates
	bool				m_MouseInsideClient;		//! Mouse cursor is inside client area

};


#endif//_WINDOW_HANDLER_H_